import ModuleTemplate from '@/utils/ModuleTemplate';
import appService from '@/utils/appService';
import systemConfig from '@/utils/config';

/** modules名称空间 */
/** 待对账单异常单 */
export const namespace = 'awaitBillClearing';
const model = {
  name: namespace,
  /** 基本属性 */
  state: {
    /** 分页数据查询条件 */
    query: {
      currentPage: 1,
      pageSize: 50,
      isException: '1'
    }
  },
  /** 从基本数据派生的数据,getters接收state作为其第一个参数，
   * 接受其他 getters 作为第二个参数，如不需要，第二个参数可以省略
   */
  getters: {},
  /** 执行同步操作，包含用于直接修改state的函数 */
  mutations: {
    /** 不是详情页返回就清空 **/
    reviseQuery(store) {
        store.query = {
            currentPage: 1,
            pageSize: 50,
            isException: '1'
        };
    },
    pushDataToList(store, data) {
      store.pageInfo.list = store.pageInfo.list.concat(data);
    }
  },
  /** 异步操作，可调用同步操作函数 */
  actions: {
    // 字典
    getKey (store, payload) {
      return new Promise((resolve, reject) => {
        appService.getRequest(`${config.dataSource}/admin/property/dictionary`, payload).then(result => {
            if (result && result.status === 200) {
              resolve(result);
            } else {
              reject(Error);
            }
          });
      });
    },
    /** 点击加载更多 **/
    getMoreList(store, payload) {
      return new Promise((resolve, reject) => {
        appService.getRequest(`${config.dataSource}/admin/settlement/bill/wait2Reconciled`, payload).then(result => {
            if (result.data.ret === 0) {
              resolve(result);
            } else {
              reject(result.data.msg);
            }
          });
      });
    },
    /** 批量处理页面 匹配规则 - 单条处理 **/
    getMatchDispose(store, payload) {
      return new Promise((resolve, reject) => {
        appService.postRequest(`${config.dataSource}/admin/settlement/bill/waitBillMatchingRule`, payload).then(result => {
            if (result && result.data.ret === 0) {
              resolve(result);
            } else {
              reject(result.data.msg);
            }
          });
      });
    },
    /** 清分规则列表list **/
    getRuleList(store, payload) {
      return new Promise((resolve, reject) => {
        appService.getRequest(`${config.dataSource}/admin/settlementrule/findPageList`, payload).then(result => {
            if (result && result.data.ret === 0) {
              resolve(result);
            } else {
              reject(result.data.msg);
            }
          });
      });
    }
  },
  /** 子模块 */
  modules: {
  }
};
const config = {
  /** 数据源，对应后端controller类的请求映射,
   * 如果不指定则默认和name一样
   */
  /* eslint-disable */
  dataSource: systemConfig.serverProxy + '/trade-settlement',
  // dataSource: systemConfig.tradeInvoicePath,
  invoiceServer: true,
  /** query函数调用的后端controller方法的请求映射 */
  queryMethod: '/admin/settlement/bill/wait2Reconciled',
  updateMethod: null,
  deleteMethod: null,
  saveMethod: null,
  getDetailMethod: '/admin/settlement/bill/detail/'
};
const moduleTemplate = new ModuleTemplate(model, config);
export const module = moduleTemplate.createModel();
